package com.ruoyi.controller.jpjs.bi_plan;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.jpjs.bi_importantmatter.ImportantMatterService;
import com.ruoyi.service.jpjs.bi_plan.PlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@RequestMapping("/biPlan")
public class PlanController extends BaseController {

    private String prefix = "jpjs/bi_plan";

    @Autowired
    private ImportantMatterService importantMatterService;

    @Autowired
    private PlanService planService;

    @GetMapping()
    public String list(ModelMap mmp) {
        mmp.put("comp", importantMatterService.getCompanyList());
        mmp.put("pro", importantMatterService.getProjectList(null));
        mmp.put("years",importantMatterService.getYears());
        mmp.put("months",importantMatterService.getMonths());
        return prefix + "/list";
    }

    @GetMapping("/backPay")
    public String backPayList(ModelMap mmp) {
        mmp.put("comp", importantMatterService.getCompanyList());
        mmp.put("years",importantMatterService.getYears());
        mmp.put("months",importantMatterService.getMonths());
        return prefix + "/backPayList";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> map) {
        return getDataTable(planService.selectPlanList(map));
    }

    @GetMapping("/add")
    public String add(ModelMap mmp) {
        mmp.put("comp", importantMatterService.getCompanyList());
        mmp.put("pro", importantMatterService.getProjectList(null));
        mmp.put("years",importantMatterService.getYears());
        mmp.put("months",importantMatterService.getMonths());
        return prefix + "/add";
    }

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestParam Map<String, String> map) {
        return toAjax(planService.addPlan(map));
    }

    @GetMapping("/edit")
    public String edit(@RequestParam String proName, ModelMap mmp) {
        mmp.put("plan", planService.selectPlan(proName));
        mmp.put("comp", importantMatterService.getCompanyList());
        mmp.put("years",importantMatterService.getYears());
        mmp.put("months",importantMatterService.getMonths());
        return prefix + "/edit";
    }

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map<String, String> map) {
        return toAjax(planService.editPlan(map));
    }

    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(@RequestParam String ids) {
        return toAjax(planService.deletePlan(ids));
    }

    @PostMapping("/uniquen")
    @ResponseBody
    public AjaxResult uniquen(@RequestParam Map<String, Object> map) {
        return AjaxResult.success(planService.uniquen(map));
    }

    @PostMapping("/backPayList")
    @ResponseBody
    public TableDataInfo backPayList(@RequestParam Map<String, Object> map) {
        return getDataTable(planService.selectPlanBackPayList(map));
    }

    @GetMapping("/backPayAdd")
    public String backPayAdd(ModelMap mmp) {
        mmp.put("comp", importantMatterService.getCompanyList());
        mmp.put("years",importantMatterService.getYears());
        mmp.put("months",importantMatterService.getMonths());
        return prefix + "/backPayAdd";
    }

    @PostMapping("/backPayAdd")
    @ResponseBody
    public AjaxResult backPayAdd(@RequestParam Map<String, String> map) {
        return toAjax(planService.addPlanBackPay(map));
    }

    @GetMapping("/backPayEdit")
    public String backPayEdit(@RequestParam String compId, ModelMap mmp) {
        mmp.put("plan", planService.selectPlanBackPay(compId));
        mmp.put("years",importantMatterService.getYears());
        mmp.put("months",importantMatterService.getMonths());
        return prefix + "/backPayEdit";
    }

    @PostMapping("/backPayEdit")
    @ResponseBody
    public AjaxResult backPayEdit(@RequestParam Map<String, String> map) {
        return toAjax(planService.editPlanBackPay(map));
    }

    @PostMapping("/backPayRemove")
    @ResponseBody
    public AjaxResult backPayRemove(@RequestParam String ids) {
        return toAjax(planService.deletePlanBackPay(ids));
    }

    @PostMapping("/uniquenBackPay")
    @ResponseBody
    public AjaxResult uniquenBackPay(@RequestParam Map<String, Object> map) {
        return AjaxResult.success(planService.uniquenBackPay(map));
    }
}
